package com.ciei.dpagm.controller;

import com.alibaba.fastjson.JSONObject;
import com.ciei.dpagm.common.controller.BaseController;
import com.ciei.dpagm.entity.Users;
import com.ciei.dpagm.service.FormLayoutService;
import com.ciei.dpagm.util.PageParam;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangyan
 * @date 2022/06/01
 */
@RestController
@RequestMapping("formLayout")
public class FormLayoutController extends BaseController {
    @Autowired
    private FormLayoutService formLayoutService;

    @RequestMapping("getFormLayoutPageList")
    public JSONObject getFormLayoutPageList(@RequestBody JSONObject page) {
        PageParam pageParam=getPageParams(page);
        return formLayoutService.getFormLayoutPageList(pageParam);
    }

    @RequestMapping("getOneFormLayout")
    public JSONObject getOneFormLayout(@RequestBody JSONObject query) {
        return formLayoutService.getOneFormLayout(query);
    }

    @RequestMapping("getAllFormLayout")
    public JSONObject getAllFormLayout(@RequestBody JSONObject query) {
        return formLayoutService.getAllFormLayout(query);
    }

    @RequestMapping("getClassificationList")
    public JSONObject getClassificationList(@RequestBody JSONObject query) {
        return formLayoutService.getClassificationList(query.getInteger("businessModule"));
    }

    @RequestMapping("getFormComponents")
    public JSONObject getFormComponents(@RequestBody JSONObject query) {
        return formLayoutService.getFormComponents(query);
    }

    /**
     * 表单设计器-新增
     */
    @RequestMapping("addFormTemplate")
    public JSONObject addFormTemplate(@RequestBody JSONObject data) {
        Users currentUser = (Users) SecurityUtils.getSubject().getPrincipal();
        return formLayoutService.addFormLayoutExcludeComponents(data,currentUser);
    }

    /**
     * 表单设计器-编辑
     */
    @RequestMapping("editFormTemplate")
    public JSONObject editFormTemplate(@RequestBody JSONObject data) {
        Users currentUser = (Users) SecurityUtils.getSubject().getPrincipal();
        return formLayoutService.editFormLayoutExcludeComponents(data,currentUser);
    }

    /**
     * 表单设计器-删除
     */
    @RequestMapping("deleteFormTemplate")
    public JSONObject deleteFormTemplate(@RequestBody JSONObject data) {
        return formLayoutService.deleteFormLayout(data.getInteger("layoutId"));
    }

    /**
     * 表单设计器-设计表单
     */
    @RequestMapping("editFormLayout")
    public JSONObject editFormLayout(@RequestBody JSONObject data) {
        Users currentUser = (Users) SecurityUtils.getSubject().getPrincipal();
        return formLayoutService.editFormLayout(data,currentUser);
    }

}
